# hello world
print("Hello world")
Hello world
# ⦁ To calculate area of a circle, square and triangle
# calculate area of circle
r = int(input("Enter circle's radius length: "))
pi = 3.14
circ_area = pi * r * r
print(f"The area of triangle is {circ_area}.")
# calculate area of rectangle
l = int(input("Enter rectangle's length: "))
b = int(input("Enter rectangle's breadth: "))
rect_area = l * b
print(f"The area of rectangle is {rect_area}.")
# calculate area of square
s = int(input("Enter square's side length: "))
sqt_area = s * s
print(f"The area of square is {sqt_area}.")
# calculate area of triangle
h = int(input("Enter triangle's height length: "))
b = int(input("Enter triangle's breadth length: "))
tri_area = 0.5 * b * h
print(f"The area of triangle is {tri_area}.")
The area of rectangle is 30.
# ⦁ To find out whether a number is Positive, Zero or Negative
num = float(input("Enter a number: "))
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")
# ⦁ To get today’s date and current time
import datetime
print(datetime.datetime.now())
2021-10-09 17:46:03.400872
# ⦁ To get the version of python on which you are working
import platform
print(platform.python_version())
3.9.7
# ⦁ To convert kilometers to miles
kilometers = float(input("Enter value (km): "))
miles = kilometers * 0.621371
print('%0.2f kilometers is equal to %0.2f miles' %(kilometers,miles))
25.00 kilometers is equal to 15.53 miles
# ⦁ To convert Celsius to Fahrenheit
tempC = float(input("Enter value (celcius): "))
fahrenheit = (tempC * 1.8) + 32
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(tempC,fahrenheit))
32.0 degree Celsius is equal to 89.6 degree Fahrenheit
# ⦁ To find whether a string is palindrome. Ask user to give the input a string
def reverse(s):
return s[::-1]
UserString = input("Enter the string to check for palindrome")
if(reverse(UserString) == UserString):
print("Its palindrome")
else:
print("Not a palindrome")
Not a palindrome
# Write a program to calculate simple interest.
p = float(input(" Principal Amount : "))
r = float(input(" Rate Of Interest : "))
t = float(input(" Time : "))
simple_interest = (p * r * t) / 100
print("\nSimple Interest for Principal Amount %0.2f = %0.2f" %(p, simple_interest))
Simple Interest for Principal Amount 5.00 = 1.25
# ⦁ Write a Python program that accepts an integer (n) and computes the value of n+nn+nnn.
i=int(input("Enter a number:"))
num= (i+ ((i*10)+i) + ((i*100)+(i*10)+i))
print(num)
#or
a = int(input("Input an integer : "))
n1 = int( "%s" % a )
n2 = int( "%s%s" % (a,a) )
n3 = int( "%s%s%s" % (a,a,a) )
print (n1+n2+n3)
615 615
# ⦁ Write a Python program to sum of three given integers. However, if two values are equal sum will be zero.
def sum(x, y, z):
if x == y or y == z or x==z:
sum = 0
else:
sum = x + y + z
return sum
print(sum(1, 2, 2))
print(sum(4, 2, 3))
0 9
# ⦁ Write a Python program to convert the distance (in feet) to inches, yards, and miles. Write a Python program to convert all units of time into seconds
ft = int(input("Input distance in feet: "))
inches = ft * 12
yards = ft / 3.0
miles = ft / 5280.0
print(" %i inches." % inches)
print(" %.2f yards." % yards)
print(" %.2f miles." % miles)
60 inches. 1.67 yards. 0.00 miles.